package com.study.test;

import com.study.bean.Boss;
import com.study.bean.Car;
import com.study.bean.Color;
import com.study.bean.Person;
import com.study.config.MainConfigOfAutowired;
import com.study.config.MainConfigOfPropertyValue;
import com.study.dao.BookDAO;
import com.study.service.BookService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author wuwenbo
 * @date 2020/4/6 - 22:53
 */
public class IOCTest_Autowired {
        ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfigOfAutowired.class);
        @Test
        public void test_Autowired() {
            printBeans(applicationContext);
            System.out.println("=========================");
            BookService bookService = applicationContext.getBean(BookService.class);
            System.out.println(bookService);

//            BookDAO bookDAO =  applicationContext.getBean(BookDAO.class);   //bookService 中的 BookDAO 和当前获取的BookDAO是同一个
//            System.out.println(bookDAO);
            System.out.println("=========================");
            Boss boss =  applicationContext.getBean(Boss.class);
            System.out.println(boss);
            Car car =  applicationContext.getBean(Car.class);
            System.out.println(car);
            Color color =  applicationContext.getBean(Color.class);
            System.out.println(color);
        }

        private void printBeans(ApplicationContext applicationContext) {
            for (String name : applicationContext.getBeanDefinitionNames()) {
                System.out.println(name);
            }
        }
    }
